<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title>后台登录</title>
    <link rel="stylesheet" type="text/css" href="/public/static/admin/layui/css/layui.css" />
    <link rel="stylesheet" type="text/css" href="/public/static/admin/css/login.css" />
    <script src="/public/static/admin/js/jquery.js"></script>
    <script src="https://www.recaptcha.net/recaptcha/api.js?onload=onloadCallback&render=explicit" async defer>
    </script>
</head>

<body>
    <div class="m-login-bg">
        <div class="m-login">
            <h3>后台系统登录</h3>
            <div class="m-login-warp">
                <form class="layui-form">
                    <div class="layui-form-item">
                        <input type="text" name="username" required lay-verify="required" placeholder="用户名" autocomplete="off" class="layui-input">
                    </div>
                    <div class="layui-form-item">
                        <input type="text" name="password" required lay-verify="required" placeholder="密码" autocomplete="off" class="layui-input">
                    </div>
                    <div class="layui-form-item">
                        <div id="google-reCaptcha"></div>
                    </div>
                    <div class="layui-form-item m-login-btn">
                        <div class="layui-inline">
                            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="login">登录</button>
                        </div>
                        <div class="layui-inline">
                            <button type="button" class="layui-btn layui-btn-primary">取消</button>
                        </div>
                    </div>
                </form>
            </div>
            <p class="copyright">Copyright 2015-2016 by XIAODU</p>
        </div>
    </div>
    <script src="../../static/admin/layui/layui.js" type="text/javascript" charset="utf-8"></script>
    <script>
        var verifyCallback = function(token) {

        };
        var onloadCallback = function() {
            grecaptcha.render('google-reCaptcha', {
                'sitekey': '6LcC80AaAAAAAE3lmv5XTkgMBVlF0c14fWSrWOfe',
                'callback': verifyCallback,
                'theme': 'light'
            });
        };
        layui.use(['form', 'layedit', 'laydate'], function() {
            var form = layui.form,
                layer = layui.layer;
            //监听提交
            form.on('submit(login)', function(data) {
                $.ajax({
                    type: "Post",
                    url: "/{$useradmin}/login/verification",
                    data: data.field,
                    dataType: "Json",
                    success: function(response) {
                        if (response['code'] == 200) {
                            window.location.href = '/{$useradmin}/Home';
                        } else {
                            var loginError = layer.alert(
                                response["message"], {
                                    skin: 'layui-layer-molv',
                                    closeBtn: 1,
                                    anim: 1,
                                    btn: ['确定'],
                                    yes: function() {
                                        grecaptcha.reset(
                                            onloadCallback
                                        );
                                        layer.close(loginError);
                                    },
                                    icon: 5,
                                    title: 'Wow 发生了一点状况'
                                })
                        }
                    }
                });
                return false;
            });

        });
    </script>
</body>

</html>